<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>

<head>
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="${pageContext.request.contextPath}/static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/bootstrapvalidator/css/bootstrapValidator.css"
          rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/jquery/jquery-1.10.2.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/bootstrapvalidator/js/bootstrapValidator.js"></script>

</head>
<body>


<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">编辑资产信息</h4>
    </div>

    <div class="panel-body">
        <form action="${pageContext.request.contextPath}/zc-asset/editAsset" id="myform" method="post"
              class="form-horizontal" role="form">
            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="assetCode" class="col-md-4 control-label">资产编号</label>
                    <div class="col-md-8">
                        <input type="hidden" id="oid" name="oid" value="${zcAsset.oid}">
                        <input type="hidden" id="createDate" name="createDate" value="${zcAsset.createDate}">
                        <input type="hidden" id="jinban" name="jinban" value="${zcAsset.jinban}">
                        <input type="text" id="assetCode" name="assetCode"
                               class="form-control" placeholder="请输入资产编号"
                               value="${zcAsset.assetCode}">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="assetNumber" class="col-md-4 control-label">序列号</label>
                    <div class="col-md-8">
                        <input type="text" id="assetNumber" name="assetNumber"
                               class="form-control" placeholder="请输入序列号"
                               value="${zcAsset.assetNumber}">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="assetName" class="col-md-4 control-label">资产名称</label>
                    <div class="col-md-8">
                        <input type="text" id="assetName" name="assetName"
                               class="form-control" placeholder="请输入资产名称"
                               value="${zcAsset.assetName}">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="type" class="col-md-4 control-label">资产类别</label>
                    <div class="col-md-8">
                        <select id="type" name="type" class="form-control">
                            <option value="">--请选择--</option>
                            <c:forEach items="${zcAssettype}" var="ztype">
                                <option value="${ztype.oid}" <c:if test="${ztype.oid eq zcAsset.type}">selected</c:if>>${ztype.typeName}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="guige" class="col-md-4 control-label">资产规格</label>
                    <div class="col-md-8">
                        <input type="text" id="guige" name="guige"
                               class="form-control" placeholder="请输入资产规格"
                               value="${zcAsset.guige}">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="produceTime" class="col-md-4 control-label">生产时间</label>
                    <div class="col-md-8">
                        <!-- 生产时间 -->
                        <input type="date" id="produceTime" name="produceTime"
                               class="form-control" placeholder="请输入生产时间"
                               value="${zcAsset.produceTime}">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="depositary" class="col-md-4 control-label">存放地</label>
                    <div class="col-md-8">
                        <select id="depositary" name="depositary" class="form-control">
                            <option value="">--请选择--</option>
                            <c:forEach items="${jcBasicdatavalue1}" var="j1">
                                <option value="${j1.oid}" <c:if test="${j1.oid eq zcAsset.depositary}">selected</c:if>>${j1.name}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="keeperName" class="col-md-4 control-label">库管</label>
                    <div class="col-md-8">
                        <input type="hidden" id="keeper" name="keeper"
                               value="${zzEmployee.oid}">

                        <div class="input-group">
                            <input type="text" id="keeperName" name="keeperName"
                                   readonly="readonly" class="form-control" placeholder="请选择库管"
                                   value="${zzEmployee.empName}"> <span
                                class="input-group-btn">
									<button class="btn btn-info" type="button"
                                            data-toggle="modal" data-target="#selectempModal">请选择</button>
								</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="price" class="col-md-4 control-label">价格</label>
                    <div class="col-md-8">
                        <input type="text" id="price" name="price"
                               class="form-control" placeholder="请输入资产价格"
                               value="${zcAsset.price}">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="regDate" class="col-md-4 control-label">入库时间</label>
                    <div class="col-md-8">
                        <!-- 入库时间 -->
                        <input type="date" id="regDate" name="regDate"
                               class="form-control" placeholder="请输入入库时间"
                               value="${zcAsset.regDate}">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="addType" class="col-md-4 control-label">资产来源</label>
                    <div class="col-md-8">
                        <select id="addType" name="addType" class="form-control">
                            <option value="">--请选择--</option>

                            <c:forEach items="${jcBasicdatavalue2}" var="j2">
                                <option value="${j2.oid}" <c:if test="${j2.oid eq zcAsset.addType}">selected</c:if>>${j2.name}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="amount" class="col-md-4 control-label">数量</label>
                    <div class="col-md-8">
                        <input type="text" id="amount" name="amount"
                               class="form-control" placeholder="请输入数量"
                               value="${zcAsset.amount}">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="remark" class="col-md-4 control-label">资产备注</label>
                    <div class="col-md-8">
							<textarea class="form-control" id="remark" name="remark"
                                      rows="5" placeholder="请输入资产备注">${zcAsset.remark}</textarea>
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="status" class="col-md-4 control-label">资产状态</label>
                    <div class="col-md-8">
                        <select id="status" name="status" class="form-control">
                            <option value="">--请选择--</option>
                            <option value="Y" ${zcAsset.status == 'Y' ? 'selected' : ''}>闲置</option>
                            <option value="U" ${zcAsset.status == 'U' ? 'selected' : ''}>使用中</option>
                            <option value="N" ${zcAsset.status == 'N' ? 'selected' : ''}>已报废</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <div class="col-md-10  col-md-offset-2">
                        <a type="button" href="javascript:history.back()" class="btn btn-info">返回</a>
                        <button type="submit" class="btn btn-success">提交信息</button>
                        <button type="reset" id="resetbtn" class="btn btn-default">取消操作</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>



<div class="modal fade" id="selectempModal" tabindex="-1" role="dialog" aria-labelledby="selectempModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="selectempModalLabel">选择员工</h4>
            </div>
            <div class="modal-body">
                <form action="" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="dept" class="col-md-4 control-label">所属部门</label>
                        <div class="col-md-5">
                            <select name="dept" class="form-control" id="dept">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="job" class="col-md-4 control-label">所属职位</label>
                        <div class="col-md-5">
                            <select name="job" class="form-control" id="job">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="emp" class="col-md-4 control-label">员工信息</label>
                        <div class="col-md-5">
                            <select name="emp" class="form-control" id="emp" size="10">
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="sub" class="btn btn-primary">确认选择</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        $.getJSON("${pageContext.request.contextPath}/bx-informal/listDeptUseSelect",function(listdept){
            var dept = $("#dept")[0];
            dept.options.length=1;
            for(var i=0;i<listdept.length;i++){
                var d = listdept[i];
                dept.options.add(new Option(d.deptName,d.oid));
            }
        });

        $("#dept").change(function(){
            $("#job")[0].options.length=1;
            $("#emp")[0].options.length=0;
            if(this.value==""){
                return;
            }
            $.getJSON("${pageContext.request.contextPath}/bx-informal/listDeptJobUseSelect",{deptid:this.value},function(listjob){
                var job = $("#job")[0];
                job.options.length=1;
                for(var i=0;i<listjob.length;i++){
                    var job1 = listjob[i];
                    job.options.add(new Option(job1.name,job1.oid));
                }
            });

            $.getJSON("${pageContext.request.contextPath}/bx-informal/listEmpUseSelete",{deptid:$("#dept").val()},function(emps){
                var emp = $("#emp")[0];
                emp.options.length=0;
                for(var i=0;i<emps.length;i++){
                    var e = emps[i];
                    emp.options.add(new Option(e.empName,e.oid));
                }
            });
        });

        $("#job").change(function(){
            $.getJSON("${pageContext.request.contextPath}/bx-informal/listEmpUseSelete2",{deptid:$("#dept").val(),jobid:this.value},function(emps){
                var emp = $("#emp")[0];
                emp.options.length=0;
                for(var i=0;i<emps.length;i++){
                    var e = emps[i];
                    emp.options.add(new Option(e.empName,e.oid));
                }
            });
        });

        $("#sub").click(function(){
            var eid=$("#emp").val();
            if(eid!=null){
                var empName=$("#emp option:selected").text();
                setempvalue(eid,empName);
                $('#selectempModal').modal('hide');
            }else{
                alert("请选择员工");
            }

        });

        $('#selectempModal').on('show.bs.modal',function() {
            $("#dept").val("");
            $("#job")[0].options.length=1;
            $("#emp")[0].options.length=0;
        });
    });
</script>






<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>

<script type="text/javascript">
    function setempvalue(eid, empName) {
        $("#keeper").val(eid);
        $("#keeperName").val(empName);

        $("#myform").data('bootstrapValidator').updateStatus('keeperName', 'NOT_VALIDATED').validateField('keeperName');
    }
</script>

</body>


<script type="text/javascript">
    $(document).ready(function() {
        $("#myform").bootstrapValidator({
            message : 'This value is not valid',
            feedbackIcons : {/*input状态样式图片*/
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                assetCode : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '资产编号不能为空'
                        },
                        remote:{
                            url:"${pageContext.request.contextPath}/zc-asset/checkAssetCode",
                            delay:1000,
                            type:'post',
                            message:'资产编号已存在!',
                            data:function(validator){
                                return {
                                    'assetCode':$("#assetCode").val(),
                                    'oid':$("#oid").val(),
                                };
                            }
                        }
                    }
                },
                assetName : {
                    validators : {
                        notEmpty : {
                            message : '资产名称不能为空'
                        }
                    }
                },
                assetNumber : {
                    validators : {
                        stringLength : {
                            max : 20,
                            message : '序列号输入过长'
                        }
                    }
                },
                guige : {
                    validators : {
                        stringLength : {
                            max : 20,
                            message : '规格输入过长'
                        }
                    }
                },
                type : {
                    validators : {
                        notEmpty : {
                            message : '请选择资产类型'
                        }
                    }
                },
                keeperName : {
                    validators : {
                        notEmpty : {
                            message : '请选择库管'
                        }
                    }
                },
                depositary : {
                    validators : {
                        notEmpty : {
                            message : '请选择存放地'
                        }
                    }
                },
                addType : {
                    validators : {
                        notEmpty : {
                            message : '请选择资产来源'
                        }
                    }
                },
                price : {
                    validators : {
                        numeric : {
                            message : '请输入正确的价格'
                        }
                    }
                },
                amount : {
                    validators : {
                        integer : {
                            message : '请输入正确的数量'
                        }
                    }
                },
                status : {
                    validators : {
                        notEmpty : {
                            message : '请选择资产状态'
                        }
                    }
                },
                remark : {
                    validators : {
                        stringLength : {
                            max : 500,
                            message : '备注输入过长'
                        }
                    }
                }
            },
            submitHandler : function(validator,form, submitButton) {
                validator.defaultSubmit();
            }
        });


        $("#resetbtn").click(function() {
            $("#myform").data("bootstrapValidator").resetForm();
        });
    });



</script>
</html>
